package cn.jtfadmin.core.modules.sys.service;


public interface SysIdGenActionService {

    /**
     * 自动生成id
     * @param type 类型
     * @return
     */
    Long autoGenId(String type);

    /**
     * 自动生成id
     * @param type 类型
     * @param length 长度
     * @return
     */
    default String autoGenId(String type, int length){
        Long id = autoGenId(type);
        String idStr = id.toString();
        if(idStr.length()>length){
            throw new RuntimeException("id超长");
        }
        StringBuilder stringBuilder = new StringBuilder();
        for(int i=0;i<length-idStr.length();i++){
            stringBuilder.append("0");
        }
        stringBuilder.append(idStr);
        return stringBuilder.toString();
    }
}
